package xm.erzhan.utils;

public class Code {

    public enum CodeEnum {

        Fail("Fail", 500),
        OK("OK", 200),

        USER_NOT_EXIST("USER_NOT_EXIST", 1000),

        RESOURCE_NOT_EXIST("RESOURCE_NOT_EXIST", 2000),
        RESOURCE_TYPE_EMPTY("RESOURCE_TYPE_EMPTY", 2001),
        RESOURCE_FOOD_LACK("RESOURCE_TYPE_EMPTY", 2002),
        RESOURCE_MINE_LACK("RESOURCE_TYPE_EMPTY", 2003),
        RESOURCE_OLI_LACK("RESOURCE_TYPE_EMPTY", 2004),
        RESOURCE_STEEL_LACK("RESOURCE_TYPE_EMPTY", 2005),
        RESOURCE_COMPLETE_FAIL("RESOURCE_COMPLETE_FAIL", 2006);

        private String status;
        private int code;

        CodeEnum(String st, int c) {
            status = st;
            code = c;
        }

        private int getCode() {
            return code;
        }

        public String getStatus() {
            return status;
        }

        static public int getCodeByType(String type) {

            int code = -1;

            for (CodeEnum c : CodeEnum.values()) {
                if (type.equals(c.getStatus())) {
                    code = c.getCode();
                    break;
                }
            }

            return code;
        }
    }
}
